<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="__ROOT__/Public/Admin/shortcut icon" href="favicon.ico">
    <link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/default.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/official.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/jquery.treetable.css" rel="stylesheet"/>

    <script>
        var CC = {
            "PUBLIC":"__PUBLIC__",
            "ROOT":"__ROOT__",
            "APP":"__APP__",
        };
    </script>

    <style>
        .nav-tabs{
            margin-bottom: 20px;
        }
        .err-tip-color{
            color:#ed2a2a;
        }
        #content-main{height: calc(100%) !important;}
        .loading{
			 width: 35px;
			 height: 35px;
			 margin: 0 auto;
			 margin-top:100px;
			 position: fixed;
			 top: 0px;
			 left: 0px;
			 right: 0px;
			 bottom: 0px;
			 margin: auto;
		}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#"><i class="fa fa-user"></i> 列表</a>
                </li>

                <li class=""><a href="{:U('Admin/Form/add')}"><i class="fa fa-plus"></i> 添加</a></li>

            </ul>
            <!-- form class="well form-search form-inline" action="{:U('Admin/Form/index')}" method="post" enctype="multipart/form-data">
                <div class="input-group">
                    <input type="text" name="keyword" placeholder="查找表单" value="{:I('request.keyword/s','')}" class="input form-control" >
                    <span class="input-group-btn">
                                    <button type="submit" class="btn btn-search"> <i class="fa fa-search"></i> 搜索</button>
                                </span>
                </div>
            </form -->
            <table class="table table-bordered table-striped text-center" id="cates-table">
               		<thead id="thead">
						<tr>
							<th width="5%"></th>
							<th width="5%">序号</th>
							<th width="30%">表单英文标识</th>
							<th width="30%">表单中文名称</th>
							<th width="40%">操作</th>
						</tr>
					</thead>
                <tbody>
                <if condition="count($list) lt 1">
                    <tr>
                        <td colspan="5">查无数据</td>
                    </tr>
                    <else/>
                    <foreach name="list" item="vo">
                        <tr data-node-id="{$vo.ID}" id="{$vo.ID}" lv="1"> 
                            <td style="padding-left:20px;" class="expander"></td>
                            <td>{$key + 1}</td>
                            <td align="left">{$vo.Name}</td>
                            <td align="left">{$vo.CName}</td>
                            <td>
                            	<!-- a class="edit-user label label-primary"  href="<?=U('Admin/FormCtr/add',array('ID'=>$vo['ID']))?>">控件添加</a -->
                            	<a class="edit-user label label-primary"  href="<?=U('Admin/FormCtr/index',array('FormID'=>$vo['ID']))?>">控件管理</a>
                                <a class="edit-user label label-success"  href="<?=U('Admin/Form/add',array('fid'=>$vo['ID']))?>">添加子表单</a>
                                <a class="edit-user label label-primary"  href="<?=U('Admin/Form/edit',array('ID'=>$vo['ID']))?>">编辑</a>
                                <a class="delete-user label label-danger"  href="javascript:deletea({$vo.ID});">删除</a>
                            </td>
                        </tr>
                        <if condition="$vo.coutsonID gt 0"><tr data-node-id="0" data-parent-id="{$vo.ID}"></tr></if>  
                    </foreach>
                </if>
                </tbody>
            </table>
        </div>
    </div>
</div>
	<script src="__ROOT__/Public/Admin/js/jquery.js"></script>  
    <script src="__ROOT__/Public/Admin/js/treetable/jquery.treetable.js"></script>
	<script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
    var GV = {
        ROOT: "__ROOT__/",
        WEB_ROOT: "__ROOT__/",
        JS_ROOT: "Public/Admin/js/"
    };
    
    	$(function(){  
            $("#cates-table").treetable({
                nodeIdAttr: "nodeId",  
                parentIdAttr: "parentId",  
                stringCollapse: "收起",  
                stringExpand: "展开",  
                expandable: true,
                //展开  
                onNodeExpand: function(){  
                    var node = this;
					if(node.children.length == 1){		
						var id = node.id;  //需要添加节点的ID 
						getDepartmentList(id);
					}
                }  
            }).on("click",".del",function(e){  
                e.preventDefault();  
                var id = $(this).closest("tr").data("node-id");               
                $("#example-basic").treetable("removeNode",id);  
            }).on("click",".add",function(e){  
                e.preventDefault();  
                var id = $(this).closest("tr").data("node-id");  //需要添加节点的ID 
                var html = loadHtml(id);  // 需要添加的节点HTML
                var node = $("#example-basic").treetable("node",id);  //需要添加节点的对象 
  
                $("#example-basic").treetable("loadBranch",node,html);  
                  
                //修改节点图标  
                $(this).closest("tr").find("td .file").removeClass("file").addClass("folder");  
            });			
        })

		function getDepartmentList(ParentID){
		    $(".loading").show();
			$.post("{:U('Form/show')}",{ParentID:ParentID},function(result){
				for(obj in result){
					var lvhtml = "";
					var lvnum = $("#"+ParentID).attr("lv");
					for(var i=0; i < lvnum * 6; i++){
						lvhtml += "&nbsp";
					}
					if(obj == (result.length-1)){
						lvhtml += "└─ ";
					}else{
						lvhtml += "├─ ";
					}
					lvnum++; 
					var html = "<tr data-node-id='" + result[obj].ID + "'  data-parent-id='" + ParentID + "'lv='" + lvnum + "'id='" + result[obj].ID +"'><td style='padding-left:20px;' class='expander'></td><td>" + result[obj].ID + "</td><td>" + lvhtml + result[obj].Name + "</td><td>" + lvhtml  + result[obj].CName + "</td><td><a class=\"edit-user label label-primary\"  href='/index.php?m=Admin&c=FormCtr&a=index&FormID=" + result[obj].ID + "'>控件管理</a> <a class=\"edit-user label label-success\" href='/index.php?m=Admin&c=Form&a=add&fid=" + result[obj].ID + "'>添加子表单</a> <a class=\"edit-user label label-primary\" href='/index.php?m=Admin&c=Form&a=edit&ID=" + result[obj].ID + "'>编辑</a> <a class=\"delete-user label label-danger js-ajax-delete\" href='javascript:deletea("+  result[obj].ID + ");''>删除</a></td></tr>"; //需要添加的HTML节点
					if(result[obj].coutsonID > 0){
						html += "<tr data-node-id='0' data-parent-id='" + result[obj].ID + "'></tr>";
					}
					var node = $("#cates-table").treetable("node",ParentID);  //需要添加节点的对象 
					$("#cates-table").treetable("loadBranch",node,html); 	
				}
				$(".loading").hide();
			});
		}
		
		//删除表单
		function deletea(id){
			$.post("{:U('Form/delete')}",{ID:id},function(result){
				if (result.status) {
	                swal({ 
						title: "操作成功！",  
						text: "删除表单！",  
						type: "success", 
						showCancelButton: false, 
						closeOnConfirm: false, 
						confirmButtonText: "返回" 
						}, function() { 
							document.location.reload();
					});
	            } else {
	                swal("操作失败！", result.info, "error");
	            }
			});
		}
		
</script>
	<script type="text/javascript" src="__ROOT__/Public/Admin/js/wind.js"></script>
	<script type="text/javascript" src="__ROOT__/Public/Admin/js/common.js"></script>
	<img src="__ROOT__/Public/Admin/img/loading.gif" class="loading" style="display:none;">
</body>
</html>